vlwkaos' digital garden

Rust - primitive_types

Boolean (bool)

let is_evening = true;

Characters (char)

let my_first_initial = 'C';
if my_first_initial.is_alphabetic() {
    println!("Alphabetical!");
} else if my_first_initial.is_numeric() {
    println!("Numerical!");
} else {
    println!("Neither alphabetic nor numeric!");
}

Array

let a: [i32; 5] = [1, 2, 3, 4, 5];
let b: = [3; 10]; // [3,3,3,3,3,3,3,3,3,3]

Slice

  • Ownership없이 데이터 배열의 구간을 참조함.

String slices

fn main() {
    let s = String::from("hello world");

    let hello = &s[0..5];
    let world = &s[6..11];
}

Tuple & destructuring

fn main() {
    let tup = (500, 6.4, 1);

    let (x, y, z) = tup;

    println!("The value of y is: {}", y);
}

이런식으로 꺼내 먹어요.

fn main() {
    let x: (i32, f64, u8) = (500, 6.4, 1);

    let five_hundred = x.0;

    let six_point_four = x.1;

    let one = x.2;
}
Rust - primitive_types